﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Db4objects.Db4o;

namespace ADB_QuanLyThuVien
{
    public class DAO_Account
    {
        public static bool isUsername(string user)
        {
            bool kq = true;
            IObjectContainer db = Db4oEmbedded.OpenFile(QLTV_System.ConnectString);
            Account acc = new Account();
            acc.Username = user;
            IObjectSet result = db.QueryByExample(acc);
            if (result.Count == 0)
                kq = false;
            db.Close();
            return kq;
        }


        internal static bool CheckAccount(Account u)
        {
            bool kq = true;
            IObjectContainer db = Db4oEmbedded.OpenFile(QLTV_System.ConnectString);
            IList<Account> list = db.Query(delegate(Account acc) // câu truy vấn theo nagative query
            {
                if (acc.Username.ToUpper() == u.Username.ToUpper() && acc.Password == u.Password)
                    return true;
                return false;
            }
            );
            if (list.Count == 0)
                kq = false;
            db.Close();
            return kq;
        }
    }
}
